package t20220310;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: DengJia
 * @Date: 2022/3/10 21:26
 * @Description:
 */

public class MainTest {
    static {
        System.out.println("666");
    }
    public static void main(String[] args) throws ClassNotFoundException {
        // fss();
        // extracted();
        Class<Son1> son1Class = Son1.class;
    }

    private static void extracted() throws ClassNotFoundException {
        Class<?> c = Class.forName("t20220310.TestImpl");
        System.out.println("c.getName() = " + c.getName());
        Class<?> sc = c.getSuperclass();
        System.out.println("sc.getName() = " + sc.getName());
        Class<?> ssc = sc.getSuperclass();
        System.out.println("ssc.getName() = " + ssc.getName());

        Test t = new TestImpl();
        if (t instanceof TestImpl) {
            TestImpl ti = (TestImpl) t;
            System.out.println("ti = " + ti);
        }

        Type type = c.getGenericSuperclass();
        System.out.println("type.getTypeName() = " + type.getTypeName());
    }

    public static void fss() {
        List<Father> list = new ArrayList<>();
        Son1 son1 = new Son1();
        Son2 son2 = new Son2();
        list.add(son1);
        list.add(son2);

        System.out.println("list = " + list);
        Class<? extends Son1> aClass = son1.getClass();
        boolean anInterface = aClass.isInterface();
        String canonicalName = aClass.getCanonicalName();
        String name = aClass.getName();
        System.exit(1);
        Class<?> superclass = aClass.getSuperclass();
        try {
            Object o = superclass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        System.out.println("canonicalName = " + canonicalName);
    }
}
